package com.example.security.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Project:spring-boot-security
 * <p>
 * Title:AdminController.java
 * <p>
 * Description:
 * <p>
 * Copyrigth:Jiang Software LTD.co Copyright (c) 2022
 * <p>
 * 
 * @version 1.0
 * @since 1.8
 * @author jiang
 * @history 2022 jiang create
 */
@Controller
@RequestMapping(value = "/admin")
public class AdminController {

	private static final Logger logger = LoggerFactory.getLogger(AdminController.class);

	/**
	 * 跳转到admin页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "/index", method = RequestMethod.GET)
	public String getIndexPage() {
		logger.debug("Received request to show admin page");
		return "/admin/index";
	}
	   /**
		 * 指定无访问权限页面
		 * 
		 * @return
		 */
		@RequestMapping(value = "/denied", method = RequestMethod.GET)
		public String getDeniedPage(ModelMap model) {
			logger.debug("Received request to show denied page");
			String name = SecurityContextHolder.getContext().getAuthentication().getName();
			model.put("loginName", name);
			return "/admin/denied";
		}
}
